package com.example.util.sms;

import com.example.util.sms.sdk.CCPRestSmsSDK;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;

/**
 * 短信发送工具
 */
public class SmsUtils {

    private static final Logger LOGGER = LoggerFactory.getLogger(SmsUtils.class);

    ///////////////////////////容联云////////////////////////////////////////////
    public static String ACCOUNT_SID = "8a216da85b602cda015b8a1bb5d411d0";
    public static String ACCOUNT_TOKEN = "370634cc574b4723a3c50371e4924230";
    public static String APP_ID = "8a216da85b602cda015b8a1bb79911d6";
    public static String SERVER_IP = "app.cloopen.com";
    public static String SERVER_PORT = "8883";


    /**
     * 容联云
     * @param phone
     * @param templateId
     * @param params
     * @return
     */
    public static boolean sendMsg(String phone, String templateId, String[] params){
        LOGGER.info("【短信发送工具类】>> 短信发送，输入参数 >> {},{},{}", phone,templateId,params);
        HashMap<String, Object> result = null;
        CCPRestSmsSDK restAPI = new CCPRestSmsSDK();
        restAPI.init(SERVER_IP, SERVER_PORT);// 初始化服务器地址和端口，格式如下，服务器地址不需要写https://
        restAPI.setAccount(ACCOUNT_SID, ACCOUNT_TOKEN);// 初始化主帐号和主帐号TOKEN
        restAPI.setAppId(APP_ID);// 初始化应用ID
        result = restAPI.sendTemplateSMS(phone,templateId ,params);
        LOGGER.info("【短信发送工具类】>> 短信通知响应信息 >> {}",result);
        if("000000".equals(result.get("statusCode"))){
            LOGGER.info("【短信发送工具类】>> 短信通知发送成功!");
            return true;
        }else{
            LOGGER.info("【短信发送工具类】>> 短信通知发送失败!");
            return false;
        }
    }


}
